package symbols;

/** 保留字, 部分运算符 */
public class Word extends Token {
    public final String lexeme;

    public Word(String lexeme, int tag) {
        super(tag);
        this.lexeme = lexeme;
    }

    @Override
    public String toString() {
        return lexeme;
    }

    public static final int TYPE = 256;// 变量类型
    public static final int ID = 257;// 变量ID

    public static final Word _if = new Word("if", Tag.IF);
    public static final Word _else = new Word("else", Tag.ELSE);
    public static final Word _while = new Word("while", Tag.WHILE);

    public static final Word ge = new Word(">=", Tag.GE);
    public static final Word le = new Word("<=", Tag.LE);
    public static final Word eq = new Word("==", Tag.EQ);
    public static final Word ne = new Word("!=", Tag.NE);

    public static final Word minus = new Word("minus", Tag.MINUS);

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((lexeme == null) ? 0 : lexeme.hashCode());
        result = prime * result + tag;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Word other = (Word) obj;
        if (lexeme == null) {
            if (other.lexeme != null)
                return false;
        } else if (!lexeme.equals(other.lexeme))
            return false;
        if (tag != other.tag)
            return false;
        return true;
    }
    
}
